package com.etc.wc.main;

import org.apache.commons.io.FileUtils;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;


public class BackupCleanTash extends TimerTask {

    @Override
    public void run() {


        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH");
        long nedf = System.currentTimeMillis();
        /**
         * 探测备份目录
         */

        File backupBaseDir = new File("D://logs/backup/");

        File[] dayBackDir = backupBaseDir.listFiles();
        try {
            //判断备份日期目录是否已超24小时
            for (File d :dayBackDir) {
                long tim = dateFormat.parse(d.getName()).getTime();
                if (nedf-tim > 24*60*60*1000L){
                   FileUtils.deleteDirectory(d);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
